package com.com.xinke.edu.petmall.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.com.xinke.edu.petmall.R;


public class TitleLayout extends RelativeLayout {
    ImageView back;
    TextView title;
    TextView rightTxt;
    public TitleLayout(Context context) {
        super(context);
    }

    public TitleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view = inflate(context, R.layout.layout_title, this);
        back=view.findViewById(R.id.back);
        title=view.findViewById(R.id.title);
        rightTxt=view.findViewById(R.id.rightTxt);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitleLayout);
        String titleTxt = a.getString(R.styleable.TitleLayout_titleTxt);
        title.setText(titleTxt);
        int titleColor = a.getColor(R.styleable.TitleLayout_titleColor, Color.BLACK);
        title.setTextColor(titleColor);

        String rightTxtTV = a.getString(R.styleable.TitleLayout_rightTxt);
        rightTxt.setText(rightTxtTV);
        int rightColor = a.getColor(R.styleable.TitleLayout_rightTxtColor, Color.BLACK);
        rightTxt.setTextColor(rightColor);
        boolean show = a.getBoolean(R.styleable.TitleLayout_show, false);
        rightTxt.setVisibility(show?VISIBLE:GONE);

        back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if(context instanceof Activity){
                    Activity activity= (Activity) context;
                    activity.finish();
                }
            }
        });
    }

    public TitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

}
